package org.prem.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class Main11 {

	public static void main(String args[]){
		StudentAddress11 studentAddress11_1 = new StudentAddress11();
		studentAddress11_1.setAddress_detail("Chennai, India");
		
		Student11 student11_1 = new Student11();
		student11_1.setStudent_name("Prem");
		student11_1.setStudentAddress11(studentAddress11_1);
		
		Student11 student11_2 = new Student11();
		student11_2.setStudent_name("Kumar");
		student11_2.setStudentAddress11(studentAddress11_1);
		
		studentAddress11_1.getStudents().add(student11_1);
		studentAddress11_1.getStudents().add(student11_2);
		
		StudentAddress11 studentAddress11_2 = new StudentAddress11();
		studentAddress11_2.setAddress_detail("Chicago, USA");
		
		Student11 student11_3 = new Student11();
		student11_3.setStudent_name("PremUS");
		student11_3.setStudentAddress11(studentAddress11_2);
		
		Student11 student11_4 = new Student11();
		student11_4.setStudent_name("KumarUS");
		student11_4.setStudentAddress11(studentAddress11_2);
		
		studentAddress11_2.getStudents().add(student11_3);
		studentAddress11_2.getStudents().add(student11_4);
		
		SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		session.save(studentAddress11_1);
		session.save(studentAddress11_2);
		session.getTransaction().commit();
		session.close();
		sessionFactory.close();
		
	}

}
